<script setup>
import {ref, watch} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const dialogVisible=ref(false);
const form =ref({})
const handleSubmit =()=>{
    axios.post("/column/saveOrUpdateColumn",form.value).then(resp=>{
      ElMessage.success(resp.data);
      handleClose();
    })
}
const handleClose =()=>{
  dialogVisible.value = false;
  form.value={}
  emits("dialogVisible",dialogVisible.value)
}
//接受父组件传过来控制弹窗的值
const props = defineProps({
  visible:{
    type: Boolean,
    required:false,
    default: false
  },
  column:{
    type:Object,
    required:false,
    default:()=>({})
  }
})
watch(()=>props.visible,(newValue)=>{
  dialogVisible.value=newValue;
})
watch(()=>props.column,(newValue)=>{
  form.value=newValue;
})
const emits =defineEmits("")
</script>

<template>
  <div>
    <!-- 弹窗 -->
    <el-dialog title="添加栏目" v-model="dialogVisible" width="30%" @close="handleClose">
      <el-form :model="form" label-width="80px">
        <el-form-item label="栏目名称:">
          <el-input v-model="form.columnName" placeholder="请输入栏目名称"></el-input>
        </el-form-item>
        <el-form-item label="顺序:">
          <el-input v-model="form.columnOrder" placeholder="请输入顺序"></el-input>
        </el-form-item>
        <el-form-item label="描述:">
          <el-input type="textarea" v-model="form.columnDescription" placeholder="请添加栏目的描述，30字以内" :rows="4"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleSubmit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<style scoped>

</style>